package com.ytjj.qmyx.supplychain.service;

import com.ytjj.qmyx.supplychain.mapper.MenuMapper;
import com.ytjj.qmyx.supplychain.mapper.entity.YxMenu;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@Slf4j
@Service
public class MenuService {
    @Resource
    private MenuMapper menuMapper;

    public List<String> selectApiCode() {
        Example example = new Example(YxMenu.class);
        example.createCriteria().andIsNotNull("apiCode");
        example.selectProperties("apiCode");
        List<YxMenu> list = menuMapper.selectByExample(example);
        if (CollectionUtils.isEmpty(list)) {
            return new ArrayList<>();
        }
        return list.stream().map(YxMenu::getApiCode).collect(Collectors.toList());
    }
}
